<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Collection;
use App\User;
use App\Models\SystemSetting;
use App\Models\Area;
/**
 *
 * @author Joker
 *        
 */
class MemberComposer
{
    /**
     * 用户中心 菜单
     * @var arrray
     */
    protected $member_menu;
    
    /**
     * 当前登陆用户
     * @var Collection
     */
    protected $userinfo;
    
    private $infos;
    
    public function __construct()
    {
        $user = Auth::user();
        
        $this->userinfo = User::find($user->id);
        if($this->userinfo->city > 0){
            $this->userinfo->cityname = Area::find($this->userinfo->city)->title;
        }
        $this->userinfo->age = user_age($this->userinfo->birth_year, $this->userinfo->birth_month);
        $this->userinfo->logo = userlogo($user->id, 'big');
        $this->userinfo->middle_logo = userlogo($user->id, 'middle');
        $this->userinfo->samll_logo = userlogo($user->id, 'samll');
        $this->member_menu = Config::get('member');
        $systemSetting = new SystemSetting();
        $this->infos = $systemSetting->getSetting("index");
    }
    
    public function compose(View $view)
    {
        $view->with('member_menu',$this->member_menu);
        $view->with('userinfo',$this->userinfo);
        $view->with('systeminfo',$this->infos);
    }
    
}